%{
#include <stdio.h>
#include <stdlib.h>
#include "hcstring.h"
#include "hclist.h"
#include "hcutil.h"
#include "hccodenode.h"
#include "hcvardefnode.h"
#include "hcidnode.h"
#include "hcconstnode.h"

extern void hcerror(char* s);
extern int yylex();
extern FILE* yyin;
%}

%defines
%name-prefix "hc"

%union {
        struct _hccodenode* codenode;
	struct _hlist* list;
}

%token<codenode> IDENTIFIER CONSTANT
%token VAR
%token SEMICOLON RBRAO RBRAC COLON COMMA DOT ASSIGN


%type<codenode> var_def
%type<codenode> expression


%%
    var_decl:   VAR var_type_spec var_def_list SEMICOLON
                {
                };

    var_type_spec:  RBRAO scoped_id RBRAC
                    {
                    }
                    | /*empty*/
                    ;

    scoped_id:  IDENTIFIER {}
                |
                scoped_id DOT IDENTIFIER { }
                ;

    var_def_list:   var_def { }
                    |
                    var_def_list COMMA var_def {}
                    ;

    var_def:    IDENTIFIER
                { $$ = (hccodenode*) hcvarfdefnode_create((hcidnode*)$1, 0, 0); }
                |
                IDENTIFIER ASSIGN expression
                { $$ = (hccodenode*) hcvarfdefnode_create((hcidnode*)$1, 0, $3);}
                ;

    expression: CONSTANT { $$ = $1; }
                ;

%%

void hcerror(s)
	char* s; {
	printf("Error: %s\n", s);
}